﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CYP.IISMonitor.Utility.SMS
{
    /// <summary>
    /// 掌上通发短信类
    /// </summary>
    public class ZhangShangTongPath : IMsg
    {
        public string SendMsg(string mobile, string contents, MSGTYPE msgType)
        {
            try
            {
                cn.f3.pi.F3WebService sms = new cn.f3.pi.F3WebService();
                cn.f3.pi.SendSMSParam smsParam = new cn.f3.pi.SendSMSParam();
                smsParam.LongCode = "";
                smsParam.ToUserText = mobile;
                smsParam.SMSContent = contents;//发送内容
                smsParam.MSGType = cn.f3.pi.MSGType.LongSMS;//要发送的短信类型
                sms.Timeout = 5000;
                MsgExtension extension = new MsgExtension().Init(msgType);//初始化短信类型
                cn.f3.pi.SResult result = sms.SendSMS(smsParam, int.Parse(extension.Uid), extension.Pwd);//发送信息返回的结果值
                int length = 1;
                if (mobile.IndexOf(',') > 0)
                {
                    length = mobile.Split(',').Length;
                }
                //DateLog.insertSMSNew(orid, aucid, mobile, contents, result, (int)msgType, extension.ExtZst); //写入数据库日志
                SMSLogWriter.Info("[掌上通]发送成功" + (length - result.ExceptionsCount) + "条");
                return "[掌上通]发送成功" + (length - result.ExceptionsCount) + "条(重复手机号只发一条)";
            }
            catch (Exception ex)
            {
                SMSLogWriter.Error("通道一底层异常，原因：" + ex.Message);
                //return "发送失败";
                throw ex;
            }
        }
    }
}
